/*++

Copyright (c) 1993  Microsoft Corporation

Module Name:

    D12.h

Abstract:



Environment:

    Kernel & user mode

Revision History:

    5-10-96 : created

--*/

#ifdef DRIVER

#define D12_NAME_MAX  64

//
// we support up to 10 pipe handles
//
#define D12_MAX_PIPES 10

//
// defines used for ISO test
//

#define D12_MAX_IRP  2
#define D12_NUM_ISO_PACKETS_PER_REQUEST  32
#define D12_MAX_STREAM_PACKET 8

#define D12_STREAM_TIMEOUT_INTERVAL  100


typedef struct _D12_PIPE {
    BOOLEAN Opened;
    UCHAR Pad[3];
    PUSBD_PIPE_INFORMATION PipeInfo;
    WCHAR Name[D12_NAME_MAX];
	LARGE_INTEGER BytesXfered;
	LARGE_INTEGER ElapsedTime;
	LARGE_INTEGER TimerStart;
	LARGE_INTEGER ElapsedCycles;
	LARGE_INTEGER CyclesStart;
	BOOLEAN		  bPerfTimerEnabled;
} D12_PIPE, *PD12_PIPE;

typedef struct _D12_RW_CONTEXT {
    PURB Urb;
    PDEVICE_OBJECT DeviceObject;
} D12_RW_CONTEXT, *PD12_RW_CONTEXT;

#define MAX_INTERFACE 2

//
// A structure representing the instance information associated with
// this particular device.
//

#define D12_MAX_PENDING_IRPS	10

typedef struct _DEVICE_EXTENSION {

    // Device object we call when submitting Urbs
    PDEVICE_OBJECT TopOfStackDeviceObject;

    PDEVICE_OBJECT PhysicalDeviceObject;

    DEVICE_POWER_STATE CurrentDevicePowerState;

    // configuration handle for the configuration the
    // device is currently in
    USBD_CONFIGURATION_HANDLE ConfigurationHandle;

    // ptr to the USB device descriptor
    // for this device
    PUSB_DEVICE_DESCRIPTOR DeviceDescriptor;

    // we support one interface
    // this is a copy of the info structure
    // returned from select_configuration or
    // select_interface
    PUSBD_INTERFACE_INFORMATION Interface;

    DEVICE_CAPABILITIES DeviceCapabilities;

    PVOID UserEvent;
    PIRP PowerIrp;
    KEVENT RemoveEvent;
    ULONG PendingIoCount;

    // Name buffer for our named Functional device object link
	// The name is generated based on the driver's class GUID
    WCHAR DeviceLinkNameBuffer[ MAXIMUM_FILENAME_LENGTH ];  // MAXIMUM_FILENAME_LENGTH defined in wdm.h

    BOOLEAN AcceptingRequests;

    UCHAR Pad[3];

    D12_PIPE PipeList[D12_MAX_PIPES];

	PIRP pendingIRP[D12_MAX_PENDING_IRPS];

} DEVICE_EXTENSION, *PDEVICE_EXTENSION;

typedef struct _D12_TRANSFER_OBJECT {
    struct _D12_STREAM_OBJECT *StreamObject;
    PIRP Irp;
    PURB Urb;
    PUCHAR DataBuffer;
} D12_TRANSFER_OBJECT, *PD12_TRANSFER_OBJECT;

typedef struct _D12_STREAM_OBJECT {
    PDEVICE_OBJECT DeviceObject;
    ULONG PendingIrps;
    PIRP StopIrp;
    PD12_TRANSFER_OBJECT TransferObjectList[D12_MAX_IRP];
    PUSBD_PIPE_INFORMATION PipeInfo;
    KDPC TimeoutDpc;
    KTIMER  TimeoutTimer;

    BOOLEAN EnableTimeoutDPC;
    BOOLEAN StreamError;
} D12_STREAM_OBJECT, *PD12_STREAM_OBJECT;

#if DBG

#define D12_KdPrint(_x_) DbgPrint _x_ ;

#ifdef NTKERN
#define TRAP() _asm {int 3}
#else
#define TRAP() DbgBreakPoint()
#endif

#else

#define D12_KdPrint(_x_)

#define TRAP()

#endif

NTSTATUS
D12_Dispatch(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp
    );

VOID
D12_Unload(
    IN PDRIVER_OBJECT DriverObject
    );

NTSTATUS
D12_StartDevice(
    IN  PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
D12_StopDevice(
    IN  PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
D12_RemoveDevice(
    IN  PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
D12_CallUSBD(
    IN PDEVICE_OBJECT DeviceObject,
    IN PURB Urb
    );

NTSTATUS
D12_PnPAddDevice(
    IN PDRIVER_OBJECT DriverObject,
    IN PDEVICE_OBJECT PhysicalDeviceObject
    );

NTSTATUS
BulkUsb_CreateDeviceObject(
    IN PDRIVER_OBJECT DriverObject,
    IN PDEVICE_OBJECT PhysicalDeviceObject,
    IN PDEVICE_OBJECT *DeviceObject
    );

NTSTATUS
D12_ConfigureDevice(
    IN  PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
D12_Write(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
D12_Create(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
D12_Read(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
D12_ProcessIOCTL(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
D12_SelectInterface(
    IN PDEVICE_OBJECT DeviceObject,
    IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
    IN PUSBD_INTERFACE_INFORMATION Interface
    );

PUSB_CONFIGURATION_DESCRIPTOR
D12_GetConfigDescriptor(
    IN PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
D12_BuildPipeList(
    IN  PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
D12_Close(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
D12_ResetPipe(
    IN PDEVICE_OBJECT DeviceObject,
    IN PD12_PIPE Pipe,
    IN BOOLEAN IsoClearStall
    );


VOID
D12_IncrementIoCount(
    IN PDEVICE_OBJECT DeviceObject
    );

LONG
D12_DecrementIoCount(
    IN PDEVICE_OBJECT DeviceObject
    );   

NTSTATUS
D12_ReconfigureDevice(
    IN  PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
D12_ProcessPowerIrp(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp
    );    

#endif


